package gupao.concurrency.utils;

import lombok.AllArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class FutureUtil {

    @AllArgsConstructor
    public static class SuccFailCount{
        final int succ;
        final int fail;
    }

    public static <T> List<T> waitFuturesComplete2(List<Future<T>> fsList) {
        List<T> rtList = new ArrayList<>();
        for (Future<T> fs : fsList) {
            try {
                rtList.add(fs.get(60, TimeUnit.SECONDS));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return rtList;
    }

    public static void waitFuturesComplete(List<Future<?>> fsList) {
        for (Future<?> fs : fsList) {
            try {
                fs.get(60, TimeUnit.SECONDS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
